var checkwarning = 0;
function AppendWarning(id,mes)
{
	$(id).parents('span').append('<span class="warning-text-field" >'+mes+'</span>');
}

jQuery.fn.validate_maxcharacter = function(i,mes) {
	var id ='#' + $(this).attr('id');
	$("input[type='submit']").click(function(){
		if ($(id).val().length>i)
		{
			if ( mes )
			{
				AppendWarning(id,mes);
			}
			else
				AppendWarning(id,'Maximum Character Of This Field Is 5');
			checkwarning ++;
		}
		if(checkwarning == 0)
			return true;
		else
			return false;
	});
	
};

jQuery.fn.validate_mincharacter = function(i,mes) {
	var id ='#' + $(this).attr('id');
	$("input[type='submit']").click(function(){
		if ($(id).val().length<i)
		{
			if ( mes )
			{
				AppendWarning(id,mes);
			}
			else
				AppendWarning(id,'Minimum Character Of This Field Is');
			checkwarning ++;
		}
		if(checkwarning == 0)
			return true;
		else
			return false;
	});
};

jQuery.fn.validate_required = function(mes) {
	var id ='#' + $(this).attr('id');
	$("input[type='submit']").click(function(){
		if ($(id).val().length=0)
		{
			if ( mes )
			{
				AppendWarning(id,mes);
			}
			else
				AppendWarning(id,'Please Enter This Field');
			checkwarning ++;
		}
		if(checkwarning == 0)
			return true;
		else
			return false;
	});
};

jQuery.fn.validate_email = function(mes) {
	var id ='#' + $(this).attr('id');
	$("input[type='submit']").click(function(){
		var email = $(id).val();
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		 if(!emailReg.test(email)) {
			if ( mes )
			{
				AppendWarning(id,mes);
			}
			else
				AppendWarning(id,'please Enter One Email ');
			checkwarning ++;
		 }
		if(checkwarning == 0)
			return true;
		else
			return false;
	});
};

jQuery.fn.validate_number = function(mes) {
	var id ='#' + $(this).attr('id');
	$("input[type='submit']").click(function(){
		var string = $(id).val();
		var numericReg = /^\d*[0-9](|.\d*[0-9]|,\d*[0-9])?$/;
		 if(!numericReg.test(string)) {
			if ( mes )
			{
				AppendWarning(id,mes);
			}
			else
				AppendWarning(id,'please Enter One Email ');
			checkwarning ++;
		 }
		 return false;
		if(checkwarning == 0)
			return true;
		else
			return false;
	});
};

jQuery.fn.validate_specialcharacter = function(mes) {
	var id ='#' + $(this).attr('id');
	$("input[type='submit']").click(function(){
		var string = $(id).val();
		var characterReg = /^\s*[a-zA-Z0-9,\s]+\s*$/;
		 if(!characterReg.test(string)) {
			if ( mes )
			{
				AppendWarning(id,mes);
			}
			else
				AppendWarning(id,'please Enter One Email ');
			checkwarning ++;
		 }
		if(checkwarning == 0)
			return true;
		else
			return false;
	});
};
jQuery.fn.validate_fakeText = function(mes) {
	var id ='#' + $(this).attr('id');
	$("input[type='submit']").click(function(){
		var string = $(id).val();
		 var fakeReg = /(.)\1{2,}/;
		 if(!fakeReg.test(string)) {
			if ( mes )
			{
				AppendWarning(id,mes);
			}
			else
				AppendWarning(id,'Please Enter correct Text');
			checkwarning ++;
		 }
		if(checkwarning == 0)
			return true;
		else
			return false;
	});
};
